package com.fary.formatter;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.format.support.FormattingConversionService;

import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

/**
 * @author Fary
 * @version 1.0
 * @description: TODO
 * @date 2022/4/13 16:50
 */
public class TestFormatter {

    public static void main(String[] args) throws ParseException {
        DateFormatter dateFormatter = new DateFormatter();
        dateFormatter.setIso(DateTimeFormat.ISO.DATE);
        System.out.println(dateFormatter.print(new Date(), Locale.CHINA));
        System.out.println(dateFormatter.parse("2020-03-26", Locale.CHINA));

        FormattingConversionService formattingConversionService = new FormattingConversionService();
        formattingConversionService.addFormatter(dateFormatter);
        Date date = formattingConversionService.convert("2020-03-26", Date.class);
    }
}
